package com.xiaomengkuan.test.controller;

import com.xiaomengkuan.test.entity.pojo.ProductDetailPicture;
import com.xiaomengkuan.test.entity.vo.ProductTagsVo;
import com.xiaomengkuan.test.service.CommentService;
import com.xiaomengkuan.test.service.ProductService;
import com.xiaomengkuan.test.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Faraj Mujey
 * -- Creation Time: 2021-01-06 9:47 下午, File Encoding: utf8 --
 */
@RestController
@CrossOrigin
@RequestMapping("test/product")
public class ProductController {
    @Resource
    ProductService productService;
    @Resource
    CommentService commentService;

    @GetMapping("/getBySort")
    public R getBySort() {
        List<ProductTagsVo> all = productService.getBySort();
        return R.OK().put("list", all);
    }

    @GetMapping("/getOneById/{id}")
    public R getOneById(@PathVariable("id") int id) {
        ProductTagsVo obj = productService.getOneById(id);
        return R.OK().put("obj", obj);
    }

    @GetMapping("/getAllDetailPictures/{id}")
    public R getAllDetailPictures(@PathVariable("id")int id){
        List<ProductDetailPicture> pictures =
                productService.getAllDetailPictures(id);
        return R.OK().put("list", pictures);
    }

    @GetMapping("/getComments/{id}")
    public R getComments(@PathVariable("id") int id){
        Map<String, Object> map = commentService.getCommentsByProductId(id);
        return R.OK().put(map);
    }

}
